<template>
  <view v-if="template">
    <s-layout
      title="拾亲Ai家庭小助手"
      :customBody="customBody()"
      navbar="inner"
      color="#000000"
      is_back
      :bgStyle="{
        color:'#F5F5F5'
      }"
    >
      <view class="w-100 flex flex-column align-center flex-sub">
        <s-block :styles="listStyle()"></s-block>
        <view class="searchs">
          <s-search-block
            :data="{
              placeholder: `全部${all_ai_total}个 请输入...`,
              borderRadius: '58rpx',
            }"
            :inputStyle="inputStyle()"
            bgColor="#FFFFFF"
            text-color="#000000"
            :radius="upx2px(58)"
            elBackground="#FFFFFF"
            :height="upx2px(80)"
            :width="'702rpx'"
            :navbar="false"
            search_url="/pages/AI/ai_search"
          ></s-search-block>
        </view>
        <s-block :styles="listStyle(25)"></s-block>
        <template1 class="w-100 flex flex-column align-center flex-sub" :all_ai_list="all_ai_list"></template1>
      </view>
    </s-layout>
  </view>
</template>

<script setup>
  import { computed, onMounted, reactive } from 'vue';
  import { onLoad, onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
  import sheep from '@/sheep';
  import $share from '@/sheep/platform/share';
  import Template1 from '@/pages/message/template/template1.vue';
  import { showAuthModal } from '@/sheep/hooks/useModal';

  // 隐藏原生tabBar
  uni.hideTabBar({
    fail: () => {
    },
  });

  const template = computed(() => sheep.$store('app').template?.home);
  const all_ai_list = computed(() => sheep.$store('AI').all_ai_list);
  const all_ai_total = computed(() => sheep.$store('AI').all_ai_total);
  const isLogin = computed(() => sheep.$store('user').isLogin);

  const upx2px = (upx) => {
    return uni.upx2px(upx);
  };
  const listStyle = (top = 10) => {
    return {
      marginTop: uni.upx2px(top),
      marginBottom: 0,
      marginLeft: 0,
      marginRight: 0,
      'border-top-left-radius': 0,
      'border-top-right-radius': 0,
      'border-bottom-left-radius': 0,
      'border-bottom-right-radius': 0,
      padding: 0,
      overflow: 'hidden',
      background: {
        type: 'color',
        bgColor: '#F6F6F6',
      },
    };
  };
  const customBody = () => {
    return {
      'display': 'flex',
      'flex-direction': 'column',
      'align-items': 'center',
    };
  };
  const inputStyle = () => {
    return {
      color: '#9F9F9F',
    };
  };

  onLoad((options) => {
    // 解析分享信息
    if (options.spm) {
      $share.decryptSpm(options.spm);
    }
    // uni.showModal({
    //   content: '禁止利用功能从事违法活动',
    //   showCancel: false,
    // });
  });

  onMounted(() => {
    // if (!isLogin.value) {
    //   showAuthModal();
    // }
  });

  onShow(() => {
    if (!isLogin.value) {
      sheep.$store('user').updateUserData();
    }
  });

  // 下拉刷新
  onPullDownRefresh(async () => {
    sheep.$store('app').init();
    sheep.$store('AI').setAllAIList();
    setTimeout(function() {
      uni.stopPullDownRefresh();
    }, 800);
  });

  onPageScroll(() => {
  });
</script>

<style></style>
